<<<<<<< HEAD
﻿#include"tcpsocket.h"
#include <iostream>
using namespace std;

int main()
{
	/* 1、 初始化socket环境  */
	init_socket();

	/* 2、创建SOCKET对象，配置要连接的服务器 */
	SOCKET clientsocket = clientSocket("192.168.124.12");

	/* 3、接下里实现收发消息的逻辑，先发再发 */
	char buf[512] = { 0 };
	while (true)
	{
		//发消息
		memset(buf, 0, 512);

		cout << "开始给服务端发消息吧：" << endl;
		cin.getline(buf, 511);

		if (send(clientsocket, buf, 511, 0) == SOCKET_ERROR)
		{
			cout << "客户端发送消息失败，错误码：" << WSAGetLastError() << endl;
			break;
		}


		//收消息
		memset(buf, 0, 512);
		if (recv(clientsocket, buf, 511, 0) > 0)
		{
			cout << "服务端说：" << buf << endl;
		}
		else
		{
			cout << "客户端接收消息失败，错误码：" << WSAGetLastError() << endl;
=======
﻿#include "tcpsocket.h"
#include <iostream>
using namespace std;


int main()
{
	//1.socket环境初始化
	init_socket();


	//2.创建SOCKET对象,配置要连接的服务器
	SOCKET clientsocket = clientSocket("192.168.124.19");

	//3.接下来实现收发消息的逻辑,先发再收
	char buf[512] = { 0 };
	while (true)
	{
		//每次收发之前都要清空数组, 不然会保留历史信息
		memset(buf, 0, 512);//sizeof(buf)

		cout << "开始给服务端发消息吧:" << endl;
		cin.getline(buf, 511);
		
		if (send(clientsocket, buf, 511, 0) ==SOCKET_ERROR )//大于零,说明收到了消息
		{
			cout << "客户端端接受消息失败,错误码: " << WSAGetLastError() << endl;
			break;
		}
	
		memset(buf, 0, 512);


		//收消息
		if (recv(clientsocket, buf, 511, 0) > 0)//大于零,说明收到了消息
		{
			cout << "服务端说: " << buf << endl;
		}
		else
		{
			cout << "客户端接受消息失败,错误码: " << WSAGetLastError() << endl;
>>>>>>> a7cf7d1e16390cd64bfc113f591a735a54316704
			break;
		}
	}

<<<<<<< HEAD
	//循环结束，要做清理
	closesocket(clientsocket);

=======
	//循环结束, 要做清理
	closesocket(clientsocket);

	//然后断开socket的系统资源
>>>>>>> a7cf7d1e16390cd64bfc113f591a735a54316704
	close_socket();

	return 0;
}
<<<<<<< HEAD

=======
>>>>>>> a7cf7d1e16390cd64bfc113f591a735a54316704
